package com.fly.order.controller;

import com.fly.common.common.ErrorConstant;
import com.fly.common.model.OrderEntity;
import com.fly.common.vo.ResponseVO;
import com.fly.order.serivce.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description 订单中心控制器
 * @author: liying.fu
 * @Date: 2018/11/24 下午4:37
 */
@RestController
@RequestMapping("/order")
@Slf4j
@Api(value = "Order Api", tags = "订单相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 获取我的订单
     *
     * @param userId 用户主键
     * @return 订单信息
     */
    @ApiOperation(value = "获取我的订单", notes = "获取我的订单")
    @GetMapping(path = "/queryOrderByUserId/{userId}")
    @PreAuthorize(value = "hasRole('ROLE_SERVER')")
    public ResponseVO<List<OrderEntity>> queryOrderByUserId(@PathVariable Long userId) {
        ResponseVO<List<OrderEntity>> responseVO = new ResponseVO<>();
        List<OrderEntity> orderEntities = orderService.queryOrderByUserId(userId);
        return responseVO.setResult(ErrorConstant.SUCCESS, ErrorConstant.SUCCESS_MSG, orderEntities);
    }
}
